<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-forms gv-forms-fluid" layout="column">
  <div class="gv-forms" layout="column">
    <form name="$ctrl.formNotification" novalidate>
      <h1>{{$ctrl.selectedNotificationSetting.name}}</h1>
      <div class="gv-form">
        <h2>Settings</h2>
        <div class="gv-form-content" layout="column">
          <div ng-if="$ctrl.selectedNotificationSetting.config_type==='GENERIC'">
            <h5>Configure the notifier you want to use:</h5>
            <div layout="column">
              <md-input-container flex>
                <label>Notifier</label>
                <input readonly ng-model="$ctrl.selectedNotificationSetting.notifier" />
              </md-input-container>
              <md-input-container flex>
                <label ng-if="$ctrl.selectedNotifier.type === 'EMAIL'">Email list (use space, ',' or ';' to separate emails)</label>
                <label ng-if="$ctrl.selectedNotifier.type === 'WEBHOOK'">URL (Gravitee will POST datas to this url)</label>
                <input ng-model="$ctrl.selectedNotificationSetting.config" aria-label="Notifier configuration" />
              </md-input-container>
              <md-input-container flex ng-if="$ctrl.selectedNotifier.type === 'WEBHOOK'">
                <md-checkbox ng-model="$ctrl.selectedNotificationSetting.useSystemProxy" aria-label="Use system proxy"
                  >Use system proxy</md-checkbox
                >
              </md-input-container>
            </div>
          </div>
          <h5>Which events would you like to subscribe for ?</h5>
          <div layout="column">
            <div ng-repeat="category in $ctrl.hooksCategories" style="margin-top: 18px">
              <h6>{{category}}</h6>
              <div layout="row" layout-wrap>
                <div flex="35" ng-repeat="hook in $ctrl.hooksByCategory[category]">
                  <md-checkbox ng-model="$ctrl.hookStatus[hook.id]" aria-label="Notification Hook">
                    <b>{{hook.label}}</b>
                    <br />
                    {{hook.description}}
                  </md-checkbox>
                </div>
              </div>
            </div>
          </div>

          <div class="md-actions gravitee-api-save-button" layout="row">
            <md-button
              class="md-raised md-primary"
              type="submit"
              permission
              permission-only="['api-notification-u', 'application-notification-u', 'environment-notification-u']"
              ng-disabled="!$ctrl.validate() || $ctrl.formNotification.$pristine"
              ng-click="$ctrl.save()"
            >
              Save
            </md-button>
            <md-button
              class="md-raised md-warn"
              type="button"
              ng-click="$ctrl.delete()"
              permission
              permission-only="['api-notification-d', 'application-notification-d', 'environment-notification-d']"
              ng-if="$ctrl.selectedNotificationSetting.config_type==='GENERIC'"
            >
              Delete
            </md-button>
          </div>
        </div>
      </div>
    </form>
  </div>
  <md-button
    permission
    permission-only="['api-notification-c', 'application-notification-c', 'environment-notification-c']"
    class="md-fab md-fab-bottom-right md-fab-scrollable"
    ng-class="{'gv-help-displayed': $ctrl.$rootScope.helpDisplayed}"
    aria-label="Add"
    ng-click="$ctrl.addDialog()"
  >
    <ng-md-icon icon="add"></ng-md-icon>
  </md-button>
</div>
